﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using FastBinarySerialization;

namespace SpeedTest
{
	// the [Serializable] tag is needed for the xmlserializer/ binaryformatter
	[Serializable]
	public class SampleBase
	{
		static SampleBase()
		{
			#region Id handler
			// register the property reader and writer
			FastBinarySerializer.Register(
				"Id",
				typeof(int),
				typeof(SampleBase),
				// create a delegate to read the property
				(instance, reader) => { ((SampleBase)instance).Id = reader.ReadInt32(); },
				// create a delegate to write the property
				(instance, writer) => { writer.Write(((SampleBase)instance).Id); });
			#endregion

			#region Name handler
			FastBinarySerializer.Register(
				"Name",
				typeof(string),
				typeof(SampleBase),
				(instance, reader) => { ((SampleBase)instance).Name = reader.ReadString(); },
				(instance, writer) => { writer.Write(((SampleBase)instance).Name); });
			#endregion
		}

		public int Id { get; set; }
		public string Name { get; set; }
	}
}
